package com.mq.consumer.config;

import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * Description:
 * Author: JH
 * Date: 2025/6/12 09:14
 */
@Configuration
public class FanoutConfig {

    // 队列 名称
    public static final String QUEUE = "xxx_queue";
    // 交换机 名称
    public static final String EXCHANGE = "xxx_exchange";

    public static final String RoutingKey = "xxx.*";


    // 声明队列
    @Bean("Queue")
    public Queue Queue() {
        return QueueBuilder.durable(QUEUE).build();
    }


    // 声明交换机
    @Bean("ExChange")
    public Exchange ExChange() {
        return ExchangeBuilder.topicExchange(EXCHANGE).durable(true).build();
    }

    @Bean
    public Binding QueueExchange(@Qualifier("Queue") Queue queue,
                                 @Qualifier("ExChange") Exchange exchange) {
        return BindingBuilder.bind(queue).to(exchange).with(RoutingKey).noargs();
    }

}
